FROM nvidia/cuda:11.8.0-cudnn8-devel-ubuntu22.04
# replace CUDA version to your CUDA version.
# You can check your CUDA version with below.
# nvcc -V

#RUN apt-get update
#RUN apt-get install -y python3
#RUN apt-get -y install python3-pip git
#RUN pip3 install torch torchvision torchaudio --index-url https://download.pytorch.org/whl/cu118
# replace CUDA version to your CUDA version.
RUN apt-get update && apt-get install -y wget && apt-get clean
COPY condarc /root/.condarc
RUN mkdir workspace
WORKDIR /workspace
RUN wget https://mirrors.tuna.tsinghua.edu.cn/anaconda/miniconda/Miniconda3-py310_25.3.1-1-Linux-x86_64.sh -O miniconda.sh && \
    bash miniconda.sh -b -p $HOME/miniconda && \
    rm -rf ./miniconda.sh 
RUN  /root/miniconda/bin/conda install -y pytorch torchvision torchaudio pytorch-cuda=11.8 -c pytorch -c nvidia && \
    /root/miniconda/bin/conda clean --all 
    

RUN /root/miniconda/bin/pip3 install fastapi uvicorn[standard] fsspec[http]==2023.1.0 -i https://mirrors.tuna.tsinghua.edu.cn/pypi/web/simple some-package && \
    /root/miniconda/bin/pip3 cache purge
    
RUN apt-get update && apt-get install -y git && apt-get clean
RUN git clone -b main https://gitee.com/liu-eric/nougat.git
COPY ./checkpoint /workspace/nougat/checkpoint
RUN echo "NOUGAT_CHECKPOINT=/workspace/nougat/checkpoint" >> ~/.bashrc && \
    echo "PATH=/root/miniconda/bin:\$PATH" >> ~/.bashrc && \
    . ~/.bashrc
WORKDIR /workspace/nougat
RUN /root/miniconda/bin/pip3 config set global.index-url https://mirrors.tuna.tsinghua.edu.cn/pypi/web/simple
COPY ./requirements.txt /workspace/nougat/
RUN /root/miniconda/bin/pip3 install -r requirements.txt
RUN /root/miniconda/bin/python3 setup.py install

EXPOSE 8503

CMD ["uvicorn", "app:app", "--host", "0.0.0.0", "--port", "8503"]
# Run this using 'docker run -it -d -p <YOUR PORT>:8503 --gpus all <IMAGE NAME>
